﻿using System.ComponentModel;

namespace AiQiuQuan.Sport.Model
{
    /// <summary>
    /// enum extension
    /// </summary>
    public static class EnumExtension
    {
        /// <summary>
        /// 获取枚举DescriptionAttribute描述
        /// </summary>
        public static string ToEnumDescription(this Enum value)
        {
            var name = value.ToString();
            var field = value.GetType().GetField(name);
            if (field == null)
            {
                return name;
            }

            var att = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute), false);
            return att == null ? field.Name : ((DescriptionAttribute)att).Description;
        }
    }
}
